package com.czk.model.iterator.practice2;

import java.util.Iterator;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/2/1 22:19
 */
public class Benz implements Car {
    /**
     * 定义存储数组
     */
    String[] array;

    @Override
    public String getName() {
        return null;
    }

    @Override
    public String brand() {
        return null;
    }

    public Benz(String[] array) {
        this.array = array;
        for (int i = 0; i < array.length; i++) {
            array[i] = i + "";
        }
    }

    /**
     * 返回迭代器
     *
     * @return
     */
    @Override
    public Iterator iterator() {
        return new BenzIterator();
    }

    /**
     * 定义内部类，迭代内部元素
     */
    private class BenzIterator implements Iterator<String> {
        private int position = 0;

        @Override
        public boolean hasNext() {
            if (position >= array.length) {
                return false;
            }
            return true;
        }

        @Override
        public String next() {
            position++;
            return array[position - 1];
        }


    }
}
